/**
 * author      : dormi330
 * date        : 2018/6/29
 * project     : mybatis
 * description : TODO
 */

package com.deep.trade.application.cart;

import com.deep.trade.cart.query.OutDtoCartItem;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.deep.trade.domain.cart.CartSku;
import com.deep.trade.domain.cart.CartQueryRepository;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CartQueryService {

    @Autowired
    private CartQueryRepository cartQueryRepository;

    public PageInfo<OutDtoCartItem> cartOfMember(String tenantCode, String memberId, int pageNum, int pageSize) throws Exception {
        PageInfo<CartSku> cartItemPage = cartQueryRepository.cartOfMember(tenantCode, memberId, pageNum, pageSize);

        List<OutDtoCartItem> outDtoCartItemList = cartItemPage.getList().stream().map(item -> {
            OutDtoCartItem outDtoCartItem = new OutDtoCartItem();
            BeanUtils.copyProperties(item, outDtoCartItem);
            return outDtoCartItem;
        }).collect(Collectors.toList());

        return new PageInfo<>(outDtoCartItemList);
    }
}
